<template>
  <!-- 左侧菜单栏 -->
  <div class="menu">
    <el-menu unique-opened :collapse="isCollapse" :default-active="$route.path" class="el-menu-vertical-demo"
      background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" router>
      <!--是否水平折叠收起菜单 会影响这里字段的显示 -->
      <h3 v-show="isCollapse">魔方</h3>
      <h3 v-show="!isCollapse">魔方医院信息系统</h3>
      <!-- <hr/> -->
      <el-menu-item :index="item.path" v-for="item in noChildren" :key="item.path" @click="clickMenu(item)">
        <i :class="'el-icon-' + item.icon"></i>
        <span slot="title">{{ item.label }}</span>
      </el-menu-item>
      <el-submenu :index="index + ''" v-for="(item, index) in hasChildren" :key="index">

        <template slot="title">
          <i :class="'el-icon-' + item.icon"></i>
          <span>{{ item.label }}</span>
        </template>
        <el-menu-item-group>
         <el-menu-item 
              :index="subItem.path" 
              v-for="(subItem,subIndex) in item.subMenus" 
              :key="subIndex"
              @click="clickMenu(subItem)"
            >
              {{subItem.label}}
            </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </div>
</template>
<script>
import store from '@/store'
    //封装的左侧导航菜单
    import navmenu from '@/config/navmenu'
    export default{
    	 //计算属性
		  computed: {
		    //没有子菜单
		    noChildren() {
          
		      return [...JSON.parse(localStorage.getItem('menu'))].filter(item => !item.subMenus)
		    },
		    //有子菜单 
		    hasChildren() {
		      return [...JSON.parse(localStorage.getItem('menu'))].filter(item => item.subMenus)
		    },
        isCollapse() {
        // 这里的数据就是从vuex取得
          return this.$store.state.tab.isCollapse
        }
		  },
		  data(){
		  	return{
          //获取菜单栏数据并赋值给menu
		  		// menu:navmenu,
          // menu:this.$store.state.login.menuList
          menu: JSON.parse(localStorage.getItem('menu'))
         
		  	}
		  },
		  methods:{
		  	clickMenu(item){
		  		this.$store.commit('selectMenu',item)
		  	},
        
		  },
      created() {
        // console.log('创造了');
        // this.menu=this.$store.state.login.menuList;
        // console.log('---',navmenu);
        // console.log('===',this.$store.state.login.menuList);
      },
    }
  
</script>

<style lang="less" scoped>
// .el-menu{
//   height: 100%;
//   border: none;

// }

// .el-menu::-webkit-scrollbar {
//      display: none;
// }
h3 {
  border-bottom: 1px solid gray;
}

.menu {
  height: 100vh;
  background-color: #ffffff;
  overflow-y: auto;
  -ms-overflow-style: none;
  /* Edge */
  scrollbar-width: none;

  /* Firefox */
  &::-webkit-scrollbar {
    display: none;
    /* WebKit */
  }
}

.el-menu {
  height: 100%;
  border: none;
}

h3 {
  color: #ffffff;
  text-align: center;
  line-height: 50px;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 225px;
  min-height: 400px;
}
</style>
